'use strict';

module.exports = function createUpdatedCollection(collectionA, objectB) {
  let obj={};
  let arr=[];
  for(let item of collectionA){
    if(item.length !== 1){
      if(!obj[item[0]]){
         obj[item[0]] = {} ;
         obj[item[0]].key =item[0] ;
         obj[item[0]].count = parseInt(item[2]) ; 
      }else if(item.length==5){
       obj[item[0]].count += parseInt(item.slice(2,4));
     } else{
        obj[item[0]].count += parseInt(item[2]);
      }
 
    }else{
     if(!obj[item]){
       obj[item]={};
       obj[item].key=item;
      obj[item].count=1;
     }else{
      obj[item].count++
     }
    }
  }
  
  for(let key in obj){
    arr.push(obj[key]);
  }
  for(let i of  arr ){
    for(let item of objectB.value)
  if(i.key==item){
      i.count= i.count-parseInt(i.count/3);
   }
 }
 return arr;
 console.log(arr);
}

